package day021.homework.p6;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class TcpClient {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1", 8888);

        OutputStream netOut = socket.getOutputStream();
        netOut.write("在吗？约不约？".getBytes());

        socket.shutdownOutput();

        InputStream netIn = socket.getInputStream();
        byte[] buf = new byte[1024];
        int len;
        while ((len = netIn.read(buf)) != -1) {
            System.out.print(new String(buf, 0, len));
        }

        socket.close();
    }
}
